<template>
  <div class="page-manage-container">
    <div class="components-main-conten">
      <div
        v-for="(item, index) in projectData.pages"
        :key="item.uuid"
        class="page-item clearfix"
        :class="{active: activePageUUID === item.uuid}"
        @click="changeActivePage(item)"
      >
        <div class="inline-block">
          <span class="page-item-index">{{ index + 1 }}</span>
          第{{ index + 1 }}页
        </div>
        <div class="page-item-btn-wrapper">
          <v-menu offset-y left>
            <template v-slot:activator="{ on, attrs }">
              <v-icon v-bind="attrs" v-on="on">
                mdi-more
              </v-icon>
            </template>
            <v-list>
              <v-hover v-slot="{ hover }">
                <v-list-item :class="{ 'on-hover': hover }">
                  <v-list-item-title @click="copyPage(item)"><v-icon>mdi-content-copy</v-icon> 复制页面</v-list-item-title>
                </v-list-item>
              </v-hover>
              <v-hover v-slot="{ hover }">
                <v-list-item :class="{ 'on-hover': hover }">
                  <v-list-item-title @click="addPage(item)"><v-icon>mdi-plus</v-icon> 新增页面</v-list-item-title>
                </v-list-item>
              </v-hover>
              <v-hover v-slot="{ hover }">
                <v-list-item :class="{ 'on-hover': hover }">
                  <v-list-item-title @click="deletePage(item)"><v-icon>mdi-delete</v-icon> 删除页面</v-list-item-title>
                </v-list-item>
              </v-hover>
            </v-list>
          </v-menu>
        </div>
      </div>
    </div>
    <div class="bottom-btn-wrapper">
      <v-btn color="primary" small @click="addPage()">新增空页面</v-btn>
    </div>
  </div>
</template>

<script>
import { mapGetters } from 'vuex'
export default {
  name: 'PageManage',
  computed: {
    ...mapGetters([
      'projectData',
      'activePageUUID',
      'activeElementUUID'
    ])
  },
  methods: {
    /**
     * 切换选中页面
     * @param item
     */
    changeActivePage(item) {
      this.$store.dispatch('h5editor/setActivePageUUID', item.uuid)
    },
    copyPage(item) {
      this.$store.dispatch('h5editor/copyPage', item.uuid)
    },
    addPage(item) {
      this.$store.dispatch('h5editor/addPage', item ? item.uuid : '')
    },
    deletePage(item) {
      this.$store.dispatch('h5editor/deletePage', item.uuid)
    }
  }
}
</script>

<style lang="scss" scoped>
.page-manage-container{
    height: 100%;
    padding-bottom: 60px;
    position: relative;
  }
  .page-item {
    height: 70px;
    line-height: 70px;
    width: 100%;
    cursor: pointer;
    transition: all 0.28s;
    border-bottom: 1px solid #e6ebed;
    background: white;
    color: #666666;
    padding: 0 10px;
    display: flex;
    &>.pull-right{
      width: 20px;
      &.custom-loading-btn{
        width: 84px;
      }
    }
    &>.inline-block{
      flex: 1;
    }
    &:hover {
      background-color: #eee;
      .page-item-btn-wrapper {
        display: block;
        opacity: 1;
      }
    }
    &.active {
      background-color: #eee;
      color: #111;
      .page-item-index{
        background: #2196F3;
        color: white;
      }
    }
    .page-item-index{
      display: inline-block;
      width: 24px;
      height: 24px;
      line-height: 24px;
      text-align: center;
      border-radius: 12px;
      background-color: #ccc;
      color: #fff;
      margin-right: 8px;
    }
  }
  .bottom-btn-wrapper{
    position: absolute;
    left: 0;
    bottom: 0;
    height: 60px;
    text-align: center;
    width: 100%;
    padding-top: 12px;
  }
  .on-hover {
    background-color: #eeeeee;
    cursor: pointer;
  }
</style>
